from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-26 14:06:55.574289
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 26, Jan, 2022
Time: 14:07:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8483
Nobs: 548.000 HQIC: -48.2792
Log likelihood: 6396.02 FPE: 8.17706e-22
AIC: -48.5556 Det(Omega_mle): 6.94888e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354683 0.069878 5.076 0.000
L1.Burgenland 0.105884 0.042485 2.492 0.013
L1.Kärnten -0.112301 0.022024 -5.099 0.000
L1.Niederösterreich 0.192328 0.088677 2.169 0.030
L1.Oberösterreich 0.129746 0.087601 1.481 0.139
L1.Salzburg 0.257966 0.044855 5.751 0.000
L1.Steiermark 0.031256 0.059158 0.528 0.597
L1.Tirol 0.101756 0.047735 2.132 0.033
L1.Vorarlberg -0.074113 0.042187 -1.757 0.079
L1.Wien 0.019824 0.077986 0.254 0.799
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058067 0.151893 0.382 0.702
L1.Burgenland -0.041400 0.092349 -0.448 0.654
L1.Kärnten 0.040503 0.047873 0.846 0.398
L1.Niederösterreich -0.205337 0.192755 -1.065 0.287
L1.Oberösterreich 0.455128 0.190415 2.390 0.017
L1.Salzburg 0.283998 0.097500 2.913 0.004
L1.Steiermark 0.114685 0.128591 0.892 0.372
L1.Tirol 0.306268 0.103760 2.952 0.003
L1.Vorarlberg 0.022655 0.091701 0.247 0.805
L1.Wien -0.025079 0.169515 -0.148 0.882
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197329 0.035612 5.541 0.000
L1.Burgenland 0.090652 0.021651 4.187 0.000
L1.Kärnten -0.007314 0.011224 -0.652 0.515
L1.Niederösterreich 0.235032 0.045192 5.201 0.000
L1.Oberösterreich 0.168949 0.044643 3.784 0.000
L1.Salzburg 0.038952 0.022859 1.704 0.088
L1.Steiermark 0.024858 0.030148 0.825 0.410
L1.Tirol 0.080940 0.024327 3.327 0.001
L1.Vorarlberg 0.054495 0.021499 2.535 0.011
L1.Wien 0.117744 0.039743 2.963 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118182 0.035775 3.303 0.001
L1.Burgenland 0.043811 0.021751 2.014 0.044
L1.Kärnten -0.013953 0.011275 -1.238 0.216
L1.Niederösterreich 0.172262 0.045399 3.794 0.000
L1.Oberösterreich 0.335491 0.044848 7.481 0.000
L1.Salzburg 0.099941 0.022964 4.352 0.000
L1.Steiermark 0.109004 0.030287 3.599 0.000
L1.Tirol 0.090901 0.024438 3.720 0.000
L1.Vorarlberg 0.060087 0.021598 2.782 0.005
L1.Wien -0.016021 0.039926 -0.401 0.688
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124073 0.067548 1.837 0.066
L1.Burgenland -0.046736 0.041068 -1.138 0.255
L1.Kärnten -0.045239 0.021290 -2.125 0.034
L1.Niederösterreich 0.141807 0.085720 1.654 0.098
L1.Oberösterreich 0.168511 0.084680 1.990 0.047
L1.Salzburg 0.282842 0.043359 6.523 0.000
L1.Steiermark 0.059777 0.057186 1.045 0.296
L1.Tirol 0.154315 0.046143 3.344 0.001
L1.Vorarlberg 0.093435 0.040780 2.291 0.022
L1.Wien 0.070772 0.075385 0.939 0.348
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.083345 0.052589 1.585 0.113
L1.Burgenland 0.022278 0.031973 0.697 0.486
L1.Kärnten 0.053026 0.016575 3.199 0.001
L1.Niederösterreich 0.190967 0.066736 2.862 0.004
L1.Oberösterreich 0.328654 0.065926 4.985 0.000
L1.Salzburg 0.035092 0.033757 1.040 0.299
L1.Steiermark 0.001680 0.044521 0.038 0.970
L1.Tirol 0.121048 0.035924 3.370 0.001
L1.Vorarlberg 0.065933 0.031749 2.077 0.038
L1.Wien 0.099615 0.058690 1.697 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173322 0.063685 2.722 0.006
L1.Burgenland 0.005303 0.038719 0.137 0.891
L1.Kärnten -0.065013 0.020072 -3.239 0.001
L1.Niederösterreich -0.107990 0.080817 -1.336 0.181
L1.Oberösterreich 0.216667 0.079836 2.714 0.007
L1.Salzburg 0.051760 0.040879 1.266 0.205
L1.Steiermark 0.251305 0.053915 4.661 0.000
L1.Tirol 0.496906 0.043504 11.422 0.000
L1.Vorarlberg 0.063832 0.038448 1.660 0.097
L1.Wien -0.082348 0.071073 -1.159 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157858 0.070397 2.242 0.025
L1.Burgenland -0.006099 0.042800 -0.142 0.887
L1.Kärnten 0.062493 0.022187 2.817 0.005
L1.Niederösterreich 0.180728 0.089335 2.023 0.043
L1.Oberösterreich -0.065895 0.088250 -0.747 0.455
L1.Salzburg 0.205237 0.045187 4.542 0.000
L1.Steiermark 0.138803 0.059597 2.329 0.020
L1.Tirol 0.055816 0.048089 1.161 0.246
L1.Vorarlberg 0.143945 0.042500 3.387 0.001
L1.Wien 0.130419 0.078564 1.660 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394669 0.041093 9.604 0.000
L1.Burgenland -0.002503 0.024984 -0.100 0.920
L1.Kärnten -0.020466 0.012952 -1.580 0.114
L1.Niederösterreich 0.203243 0.052148 3.897 0.000
L1.Oberösterreich 0.242117 0.051515 4.700 0.000
L1.Salzburg 0.033094 0.026378 1.255 0.210
L1.Steiermark -0.017591 0.034789 -0.506 0.613
L1.Tirol 0.086405 0.028071 3.078 0.002
L1.Vorarlberg 0.050978 0.024809 2.055 0.040
L1.Wien 0.033786 0.045861 0.737 0.461
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.034564 0.102525 0.166646 0.135165 0.091125 0.082687 0.030583 0.214338
Kärnten 0.034564 1.000000 -0.026961 0.133429 0.046671 0.085362 0.444040 -0.068903 0.093232
Niederösterreich 0.102525 -0.026961 1.000000 0.308455 0.126558 0.266024 0.068723 0.155654 0.282782
Oberösterreich 0.166646 0.133429 0.308455 1.000000 0.214742 0.293383 0.169197 0.134927 0.236227
Salzburg 0.135165 0.046671 0.126558 0.214742 1.000000 0.125595 0.089809 0.104330 0.126901
Steiermark 0.091125 0.085362 0.266024 0.293383 0.125595 1.000000 0.135075 0.104528 0.030337
Tirol 0.082687 0.444040 0.068723 0.169197 0.089809 0.135075 1.000000 0.063627 0.151247
Vorarlberg 0.030583 -0.068903 0.155654 0.134927 0.104330 0.104528 0.063627 1.000000 -0.005149
Wien 0.214338 0.093232 0.282782 0.236227 0.126901 0.030337 0.151247 -0.005149 1.000000